package com.nlp.visualization.core.format;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;

public class FormatUtils {

    static Gson gson = new GsonBuilder().setPrettyPrinting().create();

    public static String formatObj(String target, Object obj) throws Exception {
        switch (target) {
            case "JSON": {
                return gson.toJson(obj);
            }
            case "XML": {
                JSONObject jobj = JSONObject.fromObject(gson.toJson(obj));
                return new XMLSerializer().write(jobj);
            }
            default:
                return "";
        }
    }
}
